package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.entity.User;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user/")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam param){
        log.debug("用户登录，参数：{}", param);
       UserVO userVO = userService.login(param);
        return JsonResult.ok(userVO);
    }

    /**
     * 新增用户
     * @param param
     * @return
     */
    @PostMapping("save")
    public JsonResult sava( UserSaveParam param){
        log.debug("{}",param);
        userService.save(param);
        return JsonResult.ok();
    }
    /**
     * 查询用户
     */
    @GetMapping("select")
    public JsonResult list(UserQuery query){
        log.debug("{}",query);
        List<UserVO> userVO=userService.list(query);
        return JsonResult.ok(userVO);
    }

    /**
     * 删除用户
     * @param userId
     * @return
     */
    @PostMapping("delete/{userId}")
    public JsonResult delete(@PathVariable Long userId){
        log.debug("{}",userId);
        userService.delete(userId);
        return JsonResult.ok();
    }
    //修改员工工作状态
    @PostMapping("update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("{}",userId);
        log.debug("{}",status);
        userService.updateUser(userId,status);
        return JsonResult.ok();
    }
    @PostMapping("update/password/{userId}")
    public JsonResult updatePassword(@PathVariable Long userId){
        userService.updatePassword(userId);
        return JsonResult.ok();
    }
    @GetMapping("select/{userId}")
    public JsonResult select(@PathVariable Long userId){
       List<UserVO>  userVO=userService.select(userId);
        return JsonResult.ok(userVO);
    }
}
